/**
 * Meituan.com Inc.
 * Copyright (c) 2010-2018 All Rights Reserved.
 */
package com.tuyou.cloud.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p></p>
 *
 * @author tuyou@meituan.com
 * @version v0.1 2018-12-16 9:31 PM tuyou Exp $$
 */
@Component
public class TestFilter extends ZuulFilter {

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext requestContext = RequestContext.getCurrentContext();
//        Map<String, List<String>> requestQueryParams = requestContext.getRequestQueryParams();
//        System.out.println(requestQueryParams);

        HttpServletRequest request = requestContext.getRequest();

//        System.out.println(request.getQueryString());
        Map<String, String[]> parameterMap = request.getParameterMap();
        System.out.println(parameterMap);
//        try {
//            ServletInputStream inputStream = request.getInputStream();
//            BufferedReader bufferedInputStream = new BufferedReader(new InputStreamReader(inputStream));
//            String line = null;
//            System.out.println("参数：");
//            while ((line = bufferedInputStream.readLine()) != null) {
//                System.out.println(line);
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }


        return null;
    }

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }
}